<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>首页</title>
    <meta charset="UTF-8">
    <style>
        div{
            margin: auto;
            width: 20%;
            border: 1px black solid ;
        }
    </style>
</head>
<body style="text-align: center">
<h1 style="color: aqua">简单电商后台系统</h1>
<c:choose>
    <c:when test="${sessionScope.user eq null}">
        <h1 style="color: aqua">登录</h1>
        <form action="/user/signIn" method="post">
            <input type="text" name="username" placeholder="用户名"><br>
            <input type="password" name="password" placeholder="密码"><br>
            <input type="submit" value="登录">
            <a href="/signUp.jsp">注册</a>
        </form>
    </c:when>
    <c:otherwise>
        <p>用户名: <a href="/user/accessPage/${sessionScope.user.role}">${sessionScope.user.username}</a>&nbsp;<a
                href="/user/signOut">退出登录</a></p>
        <c:if test="${sessionScope.user.role eq 0}">
            <form action="/product/researchProducts" method="post">
                <input type="text" name="title" placeholder="请输入需要的商品名称">
                <input type="text" name="details" placeholder="商品描述">
                <select name="type">
                    <option value="">任意</option>
                    <option value="自营">自营</option>
                    <option value="第三方">第三方</option>
                </select>
                <input type="submit" value="搜索">
            </form>
            <ul style="display: inherit;list-style: none">
                <c:forEach var="product" items="${sessionScope.pagination.list}">
                    <li>
                        <div style="color: red">
                            <a style="color: black" href="/product/detailProduct/${product.id}">
                                <img width="50px" height="auto" src="/static/images/product/${product.picture}"><br>
                                    ${product.title}
                            </a>
                            <br>
                            <span style="color: gray">原价:￥${product.orginal_price}</span><span style="color: red"> 现价:￥${product.current_price}</span>
                        </div>
                    </li>
                </c:forEach>
            </ul>
            <br>
            <c:import url="/page.jsp">
                <c:param name="path" value="product/${sessionScope.pagination.sqlId}s"/>
            </c:import>
        </c:if>
        <c:if test="${sessionScope.flag eq 1}">
            <h3 style="color: blue">查询结果:</h3>
            <ul style="display: inherit;list-style: none">
                <c:forEach var="re_product" items="${sessionScope.research_products}">
                    <li>
                        <div style="color: red">
                            <a style="color: black;text-align: center" href="/product/detailProduct/${re_product.id}">
                                <img  width="50px" height="auto" src="/static/images/product/${re_product.picture}"><br>
                                    ${re_product.title}
                            </a>
                            <br>
                            <span style="color: gray">原价:￥${re_product.orginal_price}</span><span style="color: red"> 现价:￥${re_product.current_price}</span>
                        </div>
                    </li>
                </c:forEach>
            </ul>
        </c:if>
        <c:if test="${sessionScope.flag eq 2}">
            <h3 style="color: red">没有该商品</h3>
        </c:if>
    </c:otherwise>
</c:choose>

<p style="color: red">${requestScope.error}</p>
</body>
</html>